FROM python:3.11.0

LABEL maintainer="Jonathan Bereyziat <contact@bereyziat.dev>"

ENV http_proxy "http://dev.datamatrixai.com:30130"
ENV https_proxy "http://dev.datamatrixai.com:30130"


COPY ./scripts/start.sh /start.sh
RUN chmod +x /start.sh

COPY ./gunicorn_conf.py /gunicorn_conf.py

COPY ./scripts/start-reload.sh /start-reload.sh
RUN chmod +x /start-reload.sh

COPY . /app
WORKDIR /app/

ENV PYTHONPATH=/app

# Install Poetry
RUN curl -sSL https://install.python-poetry.org | POETRY_HOME=/opt/poetry python && \
    cd /usr/local/bin && \
    ln -s /opt/poetry/bin/poetry && \
    poetry config virtualenvs.create false

# Copy poetry.lock* in case it doesn't exist in the repo
COPY ./pyproject.toml ./poetry.lock* /app/

ARG ENV_CONFIG

# 允许在“dev”环境中安装开发依赖项以运行测试和 lint
RUN bash -c "if [ $ENV_CONFIG == 'dev' ] ; then poetry install --no-root ; else poetry install --no-root --without dev ; fi"

EXPOSE 80

ENV http_proxy ""
ENV https_proxy ""

# 运行启动脚本，它将检查 appprestart.sh 脚本（例如用于迁移）
# 然后使用 Uvicorn 启动 Gunicorn
CMD ["/start.sh"]